/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.core.base.config;

import org.proteusframework.core.api.config.IConfigProperty;
import org.proteusframework.core.api.config.IConfigPropertyPrototype;
import org.proteusframework.core.util.Assert;

/**
 * Runtime configuration property prototype.
 *
 * @author Tacoma Four
 */
public final class ConfigProperty implements IConfigProperty
{
    /**
     * Assigned value (runtime) of the configuration property.
     */
    private Object assignedValue;

    /**
     * Prototypical definition of the configuration property.
     */
    private IConfigPropertyPrototype prototype;

    /**
     * Constructs an immutable <code>IConfigProperty</code> for use as a runtime value based on the assigned value.
     *
     * @param prototype     Configuration property prototype to generate a runtime configuration property from with the
     *                      given assigned value
     * @param assignedValue Assigned value to give the configuration property; may be null
     */
    public ConfigProperty(final IConfigPropertyPrototype prototype, final Object assignedValue)
    {
        Assert.parameterNotNull(prototype, "Parameter 'prototype' must not be null");

        this.prototype = prototype;
        this.assignedValue = assignedValue;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object getAssignedValue()
    {
        return assignedValue;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getKey()
    {
        return prototype.getKey();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getDescription()
    {
        return prototype.getDescription();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getExample()
    {
        return prototype.getExample();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isMandatory()
    {
        return prototype.isMandatory();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object getDefaultValue()
    {
        return prototype.getDefaultValue();
    }
}
